//
//  SunTabController.m
//  Xspcf
//
//  Created by sunshine on 16/10/8.
//  Copyright © 2016年 小小算盘. All rights reserved.
//

#import "SunTabController.h"
#import "SunNavController.h"
#import "ColorButton.h"

#import "SunFirstVC.h"
#import "SunSecondVC.h"
#import "SunThirdVC.h"
#import "SunFourthVC.h"

#import "SunGesChangeVC.h"


//test

@interface SunTabController ()

@end

@implementation SunTabController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor whiteColor];
    // 背景
    NSMutableArray *colorArray1 = [@[[UIColor colorWithHexString:@"FFFFFF"],[UIColor colorWithHexString:@"FFFFFF"]] mutableCopy];
    ColorButton *cb = [[ColorButton alloc]initWithFrame:CGRectMake(0, 0,SCREENWIDTH, 44)];
    UIImage* backImage = [cb buttonImageFromColors:colorArray1 ByGradientType:leftToRight];
    [self.tabBar setBackgroundImage:backImage];
    // 阴影
    [self.tabBar setShadowImage:[[UIImage alloc] init]];
    self.tabBar.layer.shadowColor = [UIColor colorWithHexString:@"F88664"].CGColor;
    self.tabBar.layer.shadowOffset = CGSizeMake(0, -2);
    self.tabBar.layer.shadowOpacity = 0.06;
    [self setupItem];
    [self setupChilds];
    self.tabBar.selectionIndicatorImage = [[UIImage alloc]init];
}


-(void)setupChilds
{
    [self setupChildVC:[[SunFirstVC alloc]init] title:@"首页" Image:@"first_default" selectImage:@"first_select"];
    [self setupChildVC:[[SunSecondVC alloc]init] title:@"项目" Image:@"second_default" selectImage:@"second_select"];
    [self setupChildVC:[[SunThirdVC alloc]init] title:@"账户" Image:@"third_default" selectImage:@"third_select"];
    [self setupChildVC:[[SunFourthVC alloc]init] title:@"发现" Image:@"fourth_default" selectImage:@"fourth_select"];
}
-(void)setupChildVC:(UIViewController *)vc title:(NSString *)title Image:(NSString *)image selectImage:(NSString *)selectImage{
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    SunNavController *navigation = [[SunNavController alloc]initWithRootViewController:vc];
    [navigation.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -5)];
    [self addChildViewController:navigation];
}
-(void)setupItem
{
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    normalAttrs[NSForegroundColorAttributeName] = COLOR_TITLE_MINOR;
    
    NSMutableDictionary *selectAttrs = [NSMutableDictionary dictionary];
    selectAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    selectAttrs[NSForegroundColorAttributeName] = COLOR_MAIN;
    
    UITabBarItem *item =[UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectAttrs forState:UIControlStateSelected];
    
}
-(void)viewDidLayoutSubviews
{
    self.selectedViewController.view.superview.frame = self.view.bounds;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
